/*
 * Created on 2006-2-25
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.toyi.security;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.toyi.util.MenuUtil;

;
/**
 * @author yangbingxp
 * 
 * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code
 * Templates
 */
public class MenuServlet extends HttpServlet {

	public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		doPost(req, res);
	}

	public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		String moduleBh = req.getParameter(MenuUtil.getProperty("top.menu.parameter"));
		// System.out.println("moduleBh---------->" + moduleBh);
		HttpSession session = req.getSession(false);
		UserInfo userInfo = ToyiSecurityManager.getUserInfo(req);
		if (userInfo != null) {
			String menuType = MenuUtil.getProperty("menu.type");
			// System.out.println("menuType---------->" + menuType);
			String moduleListString = "";
			if (menuType.equalsIgnoreCase("tree")) {
				// System.out.println("build tree menu---------->");
				moduleListString = userInfo.getModulesByFirstModuleId(moduleBh);
			} else if (menuType.equalsIgnoreCase("xpmenu")) {
				// System.out.println("build xp menu---------->");
				moduleListString = MenuUtil.getXPMenu(userInfo.getSubModulesByFirstLevelModuleBh(moduleBh));
			} else if (menuType.equalsIgnoreCase("dropmenu")) {
				// System.out.println("build drop menu---------->");
			}
			// System.out.println("moduleListString---------->");
			// System.out.println(moduleListString);
			session.setAttribute("menu.string", moduleListString);
			req.getRequestDispatcher(SecurityConstants.getSecurityConstant(SecurityConstants.MAIN_MENU_PAGE)).forward(
					req, res);
		} else {
			res.sendRedirect(req.getContextPath() + "/"
					+ SecurityConstants.getSecurityConstant(SecurityConstants.LOGIN_PAGE));
		}

	}
}